$(function(){
	$("#close").on("click",function(){
		$("#adverpart").css("display","none");
	});

	$("#citysel").on("mouseenter",function(){
		$(this).find(".citysel-show-all").removeClass("hide");
	});

	$("#citysel").on("mouseleave",function(){
		$(this).find(".citysel-show-all").addClass("hide");
	});

	$("#close2").on("click",function(){
		$(this).closest(".citysel-show-all").addClass("hide");
	});

	var timer = null;
	$("#sear").on("keyup",function(){

		var searfirst = $(this).val();
		if(searfirst !=""){
			$("#sear-show").removeClass("hide");
		}else{
			$("#sear-show").addClass("hide");
		}
	
		clearTimeout(timer);
	
		timer = setTimeout(function(){
			jiazai(searfirst);
		},1000);
	});
	
	function jiazai(canshu){
		$.ajax({
		url: "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+canshu+"",
		type: "get",
		dataType: "jsonp",
		jsonp: "cb",
		success:function(res){
			
			$("#sear-show").html("");
			$.each(res.s,function(index,val){
				var str = val;
				var str2 = str.replace(new RegExp(canshu, 'g'),"<span class=gaoliang>"+canshu+"</span>");
				$("#sear-show").append("<a href=#>"+str2+"</a>");

			});
		},
		error: function(){
			console.log("没有数据");
		}
		});
	}

	//高亮文本测试
	// var str = "jaxjava开班啦java";
	// var lai = "java";
	// var str2 = str.replace(new RegExp(lai, 'g'),"<span class=gaoliang>java</span>");
	// var lianjie = $("<a href=#>"+str2+"</a>");
	// $("body").append(lianjie);
	

})